//
//  ConvenientPayViewController.m
//  HuLaQuan
//
//  Created by hok on 1/16/16.
//  Copyright © 2016 Jianghao. All rights reserved.
//

#import "ConvenientPayViewController.h"

//cells

#import "GenericSecondViewCollectionCell.h"

@interface ConvenientPayViewController ()

@property (weak, nonatomic) IBOutlet UICollectionView *paymentItemsView;
@property (strong, nonatomic) NSMutableArray *items;

@end

static NSString * const GenericSecondViewCollectionCellIdentifier = @"GenericSecondViewCollectionCell";
@implementation ConvenientPayViewController



- (NSMutableArray *)items
{
    if(!_items) _items= [NSMutableArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"ConvenientPaymentItems" ofType:@"plist"]];
    return _items;
}

- (void)setupUI
{
    self.title = @"便民缴费";
    
    [self.paymentItemsView registerNib:[GenericSecondViewCollectionCell nib] forCellWithReuseIdentifier:GenericSecondViewCollectionCellIdentifier];
   // self.paymentItemsView.backgroundColor = UIColorFromRGBA(kBackgroundColor, 1,0);
    self.paymentItemsView.backgroundColor = UIColorFromRGBA(kBackgroundColor, 1.);
    //Navigation Back Button
    [self setupNavBackButton];
    
}
#pragma mark - UICollectionViewDataSource
//定义展示的UICollectionViewCell的个数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    
    return self.items.count;
    
    
}
//定义展示的Section的个数
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

//每个UICollectionView展示的内容
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    if ([collectionView isEqual:self.paymentItemsView]) {
        GenericSecondViewCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:GenericSecondViewCollectionCellIdentifier forIndexPath:indexPath];
        [cell sizeToFit];
        
        
        
        cell.indexPath = indexPath;
        cell.itemTitle.text = self.items[indexPath.row][@"title"];
        cell.itemImageName = self.items[indexPath.row][@"image"];
        
        return cell;
    }
    
    return nil;
    
}
//定义每个UICollectionView 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(self.paymentItemsView.bounds.size.width /kGenericSecondViewCollectionCellRowNumber, kGenericSecondViewCollectionCellHeight);
    
    
}
//定义每个UICollectionView 的间距
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0, 0, 0, 0);
}


//返回这个UICollectionView是否可以被选择
-(BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}
#pragma mark - UICollectionViewDelegate
//UICollectionView被选中时调用的方法
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
   // NSLog(@"select %ld",indexPath.row);
    switch (indexPath.row ) {
        case 0:
            [self performSegueWithIdentifier:@"ShowElectricityPayFromCPHome" sender:self];
            break;
        case 1:
            [self performSegueWithIdentifier:@"ShowWaterPayFromCPHome" sender:self];
            break;
        case 2:
            [self performSegueWithIdentifier:@"ShowGasPayFromCPHome" sender:self];
            break;
        case 4:
            [self performSegueWithIdentifier:@"ShowPhonePayViewController" sender:self];
            break;
        case 5:
            [self performSegueWithIdentifier:@"ShowTraficPayFromCPHome" sender:self];
            break;
            
            break;
        default:
            break;
    }
    
    
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
